<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/axios.min.js"></script>
    <style>
        @import "user.css";
    </style>
    <script>
        function $(id) {
          return document.getElementById(id);
        }

        function logUser() {
          axios.get("/user/login",{
              params:{
                  userName:$("userName").value,
                  pwd:$("pwd").value
              }
          }).then(resp =>{
              if(resp.data == "ok"){
                location.href="/html/index.html"
              }
              else {
                  $("errorDiv").innerHTML="账号或密码错误"
              }
          });
        }
        function enroll() {
            $("enrollDiv").style.visibility="visible";
            $("enrollDiv").style.width = document.documentElement.clientWidth+"px"
            $("enrollDiv").style.height = document.documentElement.clientHeight+"px"
        }

        function clickUser() {
            var formObj = new FormData();
            formObj.append("name",$("name").value);
            formObj.append("pwd",$("userPwd").value);
            formObj.append("pwds",$("returnPwd").value);
            formObj.append("email",$("email").value);
            formObj.append("pic",$("myFile").files[0]);

            //设置请求头
            let config = {
                headers: {'Content-Type': 'multipart/form-data' }
            }
            axios.post("/user/add",formObj,config).then(resp =>{
                if(resp.data == "ok"){
                    location.href="/html/login.html";
                }
            });
        }
    </script>
</head>
<body>
     <div id="errorDiv" style="color: red"></div>
     用户名：<input type="text" id="userName"><br>
     密码：<input type="password" id="pwd"><br>
     <input type="submit" value="登陆" onclick="logUser()">
     <input type="submit" value="注册" onclick="enroll()">
     <div class="showDiv" id="enrollDiv">
         <div class="contentDiv">
             用户头像:<input type="file" id="myFile"><br>
             用户名:<input type="text" id="name"><br>
             用户密码：<input type="password" id="userPwd"><br>
             密码确认：<input type="password" id="returnPwd"><br>
             用户邮件:<input type="text" id="email"><br>
             <input type="submit" value="提交" onclick="clickUser()">
         </div>
     </div>
</body>
</html>